package net.root.plain.alarm;

import java.util.ArrayList;

import net.root.plain.main.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class AlarmEditAdapter extends BaseAdapter implements OnItemClickListener{
	private Context mContext;
	private ArrayList<String> mList;
	private LayoutInflater mInflater;

	public AlarmEditAdapter(Context context, AlarmDTO objects) {
		// TODO Auto-generated constructor stub
		this.mContext = context;
		this.mInflater = (LayoutInflater) mContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mList = new ArrayList<String>();
		mList.add(""+objects.getAlarmStatus());
		mList.add(objects.getAlarmTime());
		mList.add(""+objects.getAlarmRepeat());
		mList.add(objects.getAlarmBell());
		mList.add(""+objects.getAlarmVibrate());
		mList.add(objects.getAlarmLabel());
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mList.size();
	}

	@Override
	public String getItem(int position) {
		// TODO Auto-generated method stub
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public int getViewTypeCount() {
		// TODO Auto-generated method stub
		return 1;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View row = convertView;
		row = mInflater.inflate(R.layout.list_view_edit_text, parent, false);
		row = makeView(row, getItemViewType(position), position);
		return row;
	}

	@Override
	public int getItemViewType(int position) {
		// TODO Auto-generated method stub
		if (position == 5) {
			return 2;
		} else if (position == 0 || position == 4) {
			return 1;
		} else {
			return 0;
		}
	}

	public View makeView(View row, int type, int position) {
		LinearLayout ll = null;
		TextView ltv = null;
		TextView stv = null;
		CheckBox cb = null;
		EditText edt = null;
		switch (type) {
		case 0:
			ll = (LinearLayout) row
					.findViewById(R.id.list_view_edit_layout_text);
			ll.setVisibility(View.VISIBLE);
			ltv = (TextView) row.findViewById(R.id.list_view_edit_large_text);
			stv = (TextView) row.findViewById(R.id.list_view_edit_normal_text);
			break;
		case 1:
			ll = (LinearLayout) row
					.findViewById(R.id.list_view_edit_layout_checkBox);
			ll.setVisibility(View.VISIBLE);
			cb = (CheckBox) row.findViewById(R.id.list_view_edit_checkBox);
			break;
		case 2:
			ll = (LinearLayout) row
					.findViewById(R.id.list_view_edit_layout_edt);
			ll.setVisibility(View.VISIBLE);
			edt = (EditText) row.findViewById(R.id.list_view_edit_edt);
			break;
		}
		switch (position) {
		case 0:
			cb.setText("알람 켜기");
			cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
				@Override
				public void onCheckedChanged(CompoundButton buttonView,
						boolean isChecked) {
					// TODO Auto-generated method stub

				}
			});
			break;
		case 1:
			ltv.setText("시간");
			stv.setText(TimeUtil.convertString(Long.parseLong(mList.get(position))));
			break;
		case 2:
			ltv.setText("반복");
			String week=WeekUtil.week(Integer.parseInt(mList.get(position)));
			stv.setText(week);
			break;
		case 3:
			ltv.setText("벨소리");
			stv.setText(mList.get(position));
			break;
		case 4:
			cb.setText("알람 켜기");
			cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
				@Override
				public void onCheckedChanged(CompoundButton buttonView,
						boolean isChecked) {
					// TODO Auto-generated method stub

				}//ㅇ
			});
			break;
		case 5:
			edt.setHint("라벨");
			break;
		}
		return row;
	}
	
	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		// TODO Auto-generated method stub
		
	}
}